import { _decorator, Component, Label, NodeEventType, sp, AudioSource } from 'cc';
const { ccclass, property } = _decorator;
@ccclass('HelloWorld')
export class HelloWorld extends Component {
    soundPlayer: AudioSource = new AudioSource();
    onLoad() {
        let mark = this.node.getChildByName('Mark').getComponent(Label);
        let hero = this.node.getChildByPath('Game/Hero').getComponent(sp.Skeleton);
        this.node.getChildByName('ButtonZh').on(NodeEventType.TOUCH_START, async () => {
            await gi.langLoad('Zh');   //切换到Zh
            gi.langRelease('En');      //释放En资源
            gi.langFormat(mark, '=>', 233, '啊', '哦');    //将mark文本的'=>'依次替换为233, '啊', '哦'
            let audioClip = gi.langAsset('Audio', 'win');  //获取音频资源
            this.soundPlayer.playOneShot(audioClip);       //播放音频
            hero.setAnimation(0, '攻击3');  //设置spine初始动作
        }, this);
        this.node.getChildByName('ButtonEn').on(NodeEventType.TOUCH_START, async () => {
            await gi.langLoad('En');   //切换到En
            gi.langRelease('Zh');      //释放Zh资源
            gi.langFormat(mark, '<+>', 666, 'lll', '999'); //将mark文本的'<+>'依次替换为666, 'lll', '999'
            let audioClip = gi.langAsset('Audio', 'win');  //获取音频资源
            this.soundPlayer.playOneShot(audioClip);       //播放音频
            hero.setAnimation(0, '攻击');   //设置spine初始动作
        }, this);
    }
}